//
//  SQPageView.swift
//  SQPageView
//
//  Created by ToothBond on 2017/4/24.
//  Copyright © 2017年 rensq. All rights reserved.
//

import UIKit

class SQPageView: UIView {
    
    // MARK: - 属性
    var titles : [String]
    var style : SQPageStyle
    var childVCs : [UIViewController]
    var parentVC : UIViewController

    // MARK: - 构造函数
    // 在构造函数调用super.init()之前，必须包桌所有的属性有被初始化
    init(frame: CGRect, titles : [String], style : SQPageStyle, childVCs : [UIViewController], parentVC : UIViewController) {
        self.titles = titles
        self.style = style
        self.childVCs = childVCs
        self.parentVC = parentVC
        super.init(frame: frame);
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

// MARK: - 设置UI界面
extension SQPageView {
    fileprivate func setupUI() {
        let titleFrame = CGRect(x: 0, y: 0, width: frame.width, height: style.titleHeight)
        let titleView = SQTitleView(frame: titleFrame, titles: titles, style: style)
        titleView.backgroundColor = UIColor.orange
        addSubview(titleView)
        
        let contentFrame = CGRect(x: 0, y: titleFrame.maxY, width: frame.width, height: bounds.height - style.titleHeight)
        let contentView = SQContentView(frame: contentFrame, childVCs: childVCs, parentVC: parentVC)
        contentView.backgroundColor = UIColor.red
        addSubview(contentView)
        titleView.delegate = contentView
        contentView.delegate = titleView
        
        
    }
}
